package com.bilgeadam.customtag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author Bora SAYINER
 * @since Jan 17, 2015 7:02:43 PM
 * @version 1.0
 */
public class TextFieldTag extends SimpleTagSupport {

	private String text;
	private String placeHolder;
	private boolean password;
	private boolean required;

	public TextFieldTag() {
		setText("");
		setPlaceHolder("");
		setPassword(false);
	}

	@Override
	public void doTag() throws JspException, IOException {
		JspWriter writer = getJspContext().getOut();
		writer.print("<form class='pure-form'>");
		writer.print(String.format("<input type='%s' placeHolder='%s' value='%s' required='%s' onBlur='function(){}'/>", password ? "password" : "text", placeHolder, text, required ? "true" : ""));
		writer.print("</form>");
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getPlaceHolder() {
		return placeHolder;
	}

	public void setPlaceHolder(String placeHolder) {
		this.placeHolder = placeHolder;
	}

	public boolean isPassword() {
		return password;
	}

	public void setPassword(boolean password) {
		this.password = password;
	}

	public boolean isRequired() {
		return required;
	}

	public void setRequired(boolean required) {
		this.required = required;
	}
}
